// wtkdisplay.hpp
//

#ifndef _WTKDISPLAY_HPP
#define _WTKDISPLAY_HPP

#include "wtk/wtkbase.hpp"
#include "wtk/wtklayout.hpp"
#include "wtk/wtkrootwidget.hpp"
#include "wtk/wtkfpscounter.hpp"

namespace wtk
{
  class Display;
  class Application;
  class WM;
  class Widget;
  class Font;


  
  // Display
  //
  class WTK_API Display
  {
    friend WM;
    friend Widget;
    
  public:
    Display ( const wgl::WindowSettings &settings );
    Display ( int width,
              int height );
    ~Display ();

    bool is_open () { return wgl_window.is_shown(); }
    void get_real_size ( int &width,
                         int &height ) const
    { return wgl_window.get_real_size(width, height); }
    
    // [fixme] useless?
    Uint32 get_sdl_window_id () const { return wgl_window.get_sdl_window_id(); }
    
    // [FIXME] should be private?
    Widget *get_root_widget () { return &root_widget; }
    void set_top_widget_layout ( Widget &widget,
                                 bool fullscreen );
    
    bool open ();
    void close ();

    void set_focus_widget ( Widget *widget );
    Widget *get_focus_widget () { return focus_widget; }

    Widget *get_widget_at ( int x,
                            int y,
                            int *rx,
                            int *ry );
    
  private:
    Application &application;
    wgl::Window wgl_window{};

    RootLayout root_layout;
    RootWidget root_widget;

    std::shared_ptr<wgl::Font> font;
    FPSCounter<200> fps_counter;
    
    Widget *focus_widget{nullptr};
    
    Display ( Application &application,
              const wgl::WindowSettings &settings );

    void update ();
  };
}

#endif
